function do_hook() {

    var getMD516 = Module.findExportByName("libkeyinfo.so", "getMD516");

    console.log('getMD516 addr = ', getMD516);
    if (getMD516) {
        Interceptor.attach(getMD516, {
            onEnter: function (args) {
                console.log('2.getMD5参数：', hexdump(args[1], {length: args[2].toInt32()}), "\n");
                // console.log('key getMD5 参数：', hexdump(args[1]), "\n");
            },
            onLeave: function (retval) {
                // console.log('3.getMD5 返回值：', hexdump(retval), "\n");
                console.log('getMD5=key 返回值：', hexdump(retval, {length: 16}), "\n");
            }
        });
    }

    var rand16Str = Module.findExportByName("libkeyinfo.so", "rand16Str");
    console.log('rand16Str addr = ', rand16Str);
    if (rand16Str) {
        Interceptor.attach(rand16Str, {
            onEnter: function (args) {
                this.x1 = args[0]
            },
            onLeave: function (retval) {
                // console.log('5.rand16Str 返回值：', hexdump(this.x1), "\n");
                console.log('rand16Str=iv 返回值：', hexdump(this.x1, {length: 16}), "\n");

            }
        });
    }


    var base64_encode = Module.findExportByName("libkeyinfo.so", "base64_encode");
    console.log('base64_encode = ', base64_encode)
    if (base64_encode) {
        Interceptor.attach(base64_encode, {
            onEnter: function (args) {
                console.log("-----------------------base64---------------------------");
                console.log('base64参数1：', hexdump(args[0], {length: args[1].toInt32()}), "\n");
                console.log('base64参数2', parseInt(args[1]), "\n");
            },
            onLeave: function (retval) {
                // console.log('5.rand16Str 返回值：', hexdump(this.x1), "\n");
                console.log('base64返回值：', Memory.readCString(retval), "\n");

            }
        });
    }
}

function delay_hook(so_name, hook_func) {
    var dlopen = Module.findExportByName(null, "dlopen");
    var android_dlopen_ext = Module.findExportByName(null, "android_dlopen_ext");

    Interceptor.attach(dlopen, {
        onEnter: function (args) {
            var path_ptr = args[0];
            var path = ptr(path_ptr).readCString();
            // console.log("[dlopen:]", path);
            this.path = path;
        }, onLeave: function (retval) {
            if (this.path.indexOf(so_name) !== -1) {
                console.log("[dlopen:]", this.path);
                hook_func();

            }
        }
    });

    Interceptor.attach(android_dlopen_ext, {
        onEnter: function (args) {
            var path_ptr = args[0];
            var path = ptr(path_ptr).readCString();
            this.path = path;
        },
        onLeave: function (retval) {
            if (this.path.indexOf(so_name) !== -1) {
                console.log("\nandroid_dlopen_ext加载：", this.path);
                hook_func();
            }
        }
    });
}


function hook_java() {
    Java.perform(function () {
        var ByteString = Java.use("com.android.okhttp.okio.ByteString");
        var Cipher = Java.use("javax.crypto.Cipher");
        Cipher.doFinal.overload('[B').implementation = function (data) {
            console.log("-----------------------AES加密---------------------------");
            console.log("AES明文：", ByteString.of(data).utf8());

            var res = this.doFinal(data);

            console.log('AES密文：', ByteString.of(res).hex());

            return res;
        }

    });
}

delay_hook("libkeyinfo.so", do_hook);
hook_java()


// frida -H 127.0.0.1:8877 -l  16_hook_complete.js -f com.achievo.vipshop